package banner

import (
	"parking-lot-go-admin/controller"
	"parking-lot-go-admin/model"
	"parking-lot-go-admin/model/dingtalk"

	"github.com/gin-gonic/gin"
)

func UpdateBanner(c *gin.Context) {

	id := c.PostForm("id")
	sort := c.PostForm("sort")

	//获取上传文件
	randomFileName, err := controller.GetUploadFile(c, "fileList")
	if err != nil {
		controller.Fail(c, err.Error())
		return
	}

	var dingtalkBannerStruct dingtalk.DingtalkBannerStruct
	model.UpdateModelData(
		model.Db,
		dingtalkBannerStruct.TableName(),
		map[string]interface{}{
			"id": id,
		},
		map[string]interface{}{
			"image_path": randomFileName,
			"sort":       sort,
		},
	)

	controller.Success(c, "")
}
